package webservice

import (
	"github.com/kataras/iris"
	"github.com/kongyixueyuan.com/kongyixueyuan/web/repositorie"
)

type UserService struct {
	ctx  iris.Context
	repo *repositorie.Userrepostorie
}

func NewUserService(context iris.Context) *UserService {
	return &UserService{ctx: context, repo: repositorie.NewUserrepostorie()}
}

func (u *UserService) Login() bool {
	user := u.ctx.URLParam("user")
	p := u.ctx.URLParam("password")
	result := u.repo.Login(user)
	if result.Password == p {
		return true
	} else {
		return false
	}
}

func (u *UserService) Register() {
	user := u.ctx.URLParam("user")
	pass := u.ctx.URLParam("password")
	u.repo.Register(user, pass)

}
